package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.utils.FastDFSUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: 李旭
 * @create: 2021-07-06 09:11
 **/
@RestController
@RequestMapping("/admin/product")
public class FileController {

    @Value("${img.url}")
    private String imgUrl;

    //文件的上传
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) throws Exception{
        String ext = FilenameUtils.getExtension(file.getOriginalFilename());
        String fileId = FastDFSUtils.upload(file.getBytes(), ext);
        System.out.println(imgUrl + fileId);
        return Result.ok(imgUrl + fileId);
    }
}
